<?php echo $this->render($this->includeDir . '/toolbar.php');?>
<?php echo $this->flashMessage();?>
<?php 
	
	$arrParam = $this->arrParam;
	
	$avatar			= $this->formFile('avatar',array('class'=>'floatLeft' ));
	$password		= $this->formPassword('password',$this->Item['password'],array('class'=>'width-200 bg-green2 floatLeft' ));
	$email			= $this->formText('email',$this->Item['email'],array('class'=>'width-300 bg-green2 floatLeft' ));
	$first_name		= $this->formText('first_name',Zendvn_Filter_Filter::filterContent($this->Item['first_name']),array('class'=>'width-200 floatLeft' ));
	$last_name		= $this->formText('last_name',Zendvn_Filter_Filter::filterContent($this->Item['last_name']),array('class'=>'width-200 floatLeft' ));
	
	$birthday		= $this->formText('birthday',$this->Item['birthday'],array('class'=>'width-200 floatLeft' ));
	 	 	 	 		 	 	 	
	$groupID 		= $this->groupID;
	if($groupID == '' || $groupID == 0){				
		$groupID = $this->Item['group_id'];
	}
	$group_id		= $this->cmsSelect('group_id',$groupID,array('class'=>'width-200 floatLeft bg-green2' ),$this->sblGroup);
	
	$ext_group = $this->Item['ext_group'];
	
	if(count($ext_group) == 0){
		$ext_group = $this->extGroupID;
	}
	
	$ext_group		= $this->cmsSelect('ext_group',$ext_group,
										 array('class'=>'width-200 floatLeft','size'=>10, 'multiple'=>'multiple' ),
										 $this->sblExtGroup);
	
	$options 		= array('inactive'=>$this->translate('Inactive'),
							'active'=>$this->translate('Active'),
							'lock'=>$this->translate('Lock'),
							);	
	$status 		= $this->formSelect('status',$this->Item['status'],array('class'=>'width-150'),$options);
	
	$sign			= Zendvn_Filter_Filter::filterContent($this->Item['sign'],'filter');
	$sign			= $this->tinyMce('sign',$sign,array('style'=>"width: 100%; height: 350px;"));
	$sign			= '<div id="d_sign" style="width:98%; float: left">' . $sign . '</div>';
	
	$configTooltip = new Zendvn_Controller_Config(array('module'=>$arrParam['module'],'fileConfig'=>'user.ini'));
	
	$arrTooltip = $configTooltip->getConfig('tooltip');
	if(count($arrTooltip)>0){
		foreach ($arrTooltip as $key => $val){
			$attribs = array();
			if($key=='d_sign') $attribs = array('leftOffset'=>-305);
			$formHelp  .= $this->cmsFormHelp('.form-table #' . $key, $this->translate($val), $attribs);
		}
	}
	 if(count($this->errors)>0){	
	 	foreach ($this->errors as $key => $val){	 
	 		$val = Zendvn_Filter_Filter::filterContent($val,'filter');
	 		$$key .= $this->cmsError($key,$val);	
	 		$selector = '.form-table #' . $key . '-error';
	 		$options = array('type'=>'error','name'=>'#' .$key);
	 		$formHelp  .= $this->cmsFormHelp($selector, $this->translate($val),null,$options);
	 		
	 	}
	 }

	 if($this->arrParam['action'] == 'edit'){
	 	$configObj = $this->config;
	 	
	 	$itemConfig = $configObj->getConfig('config');
		
		$current_avatar = '<div id="load-content-avatar" class="clr width-150 center">';
		if(!empty($this->Item['avatar'])){
			$avatarUrl = $itemConfig['thumbUrl3'] . '/' . $this->Item['avatar'];
			$removeLink = $this->url(array('action'=>'remove-pic','file'=>$this->Item['avatar']));
			$current_avatar .= '<br>' . $this->cmsImage('avatar',$avatarUrl,array('width'=>'75px'))
							. '<br><a  class="remove" href="javascript:loadPage(\'div#load-content-avatar\',\'' . $removeLink . '\')">remove</a>';
		}
		
		$current_avatar .= $this->formHidden('current_avatar',$this->Item['avatar'])
						. '</div>';
		$avatar .=	$current_avatar;	
	 	
	}
	
	 $arrRow 	= array(
	 					array('label'=>$this->translate('Email'),'input'=>$email),
				 		array('label'=>$this->translate('Password'),'input'=>$password),
						array('label'=>$this->translate('Group default'),'input'=>$group_id),						
//						array('label'=>$this->translate('Extend group'),'input'=>$ext_group),						
						array('label'=>$this->translate('Avatar'),'input'=>$avatar),						
						array('label'=>$this->translate('First name'),'input'=>$first_name),						
						array('label'=>$this->translate('Last name'),'input'=>$last_name),						
						array('label'=>$this->translate('Birthday'),'input'=>$birthday),						
						array('label'=>$this->translate('Status'),'input'=>$status),						
						array('label'=>$this->translate('Sign'),'input'=>$sign),						
					 );
	  	 	 	 	 	 	 	 	
	$tdForm 	= $this->partialLoop('row.php',$arrRow);
?>
<div id="element-box">
	<div class="m">
		<div class="form-table">
            	<fieldset class="admin-fieldset">
                <legend class="admin-legend"><?php echo $this->translate('Form detail')?></legend>
            	<table width="100%" border="0">
                	<?php echo $tdForm;?>
                </table>
                <div class="clr"></div>
                </fieldset>             
            </div>
            <div class="clr"></div>
	</div>
</div>
<script>
$(document).ready(function() {
	<?php echo $formHelp;?>
});
$(function() {
	var today = new Date();
    var year = today.getFullYear()-112;
   	var maxYear = today.getFullYear();
	$('#birthday').datepicker({  
		dateFormat: 'yy-mm-dd',
		changeMonth: true,
		changeYear: true,	
	   	minDate: new Date(year, 1 - 1, 25),
	   	maxDate: new Date(maxYear, 12 - 1, 31),
	    yearRange: "-112:+00"
	});
});		
</script>
